package csl.blog.server.config.redis;

import java.util.List;

/**
 * 分布式锁
 * @author chensl
 * @date 2023-05-11 17:30:33
 * @description
 */
public interface IDistributedLocker {

    /**
     * 获取锁
     * @param key  锁的名称
     * @param worker 获取锁后的处理类
     * @return 处理完具体的业务逻辑要返回的数据
     */
    <T> T lock(T key, IWorker<T> worker) throws Exception;

    /**
     * @param lockTime 锁时间
     */
    <T> T lock(T key, IWorker<T> worker, int lockTime) throws Exception;

    /**
     * @param fair 是否公平
     */
    <T> T lock(T key, IWorker<T> worker, int lockTime, boolean fair) throws Exception;

    /**
     * 获取联锁
     * @param keys 锁的名称
     * @param worker 获取锁后的处理类
     * @return 处理完具体的业务逻辑要返回的数据
     */
    <T> T lock(List<T> keys, IWorker<T> worker) throws Exception;

    <T> T lock(List<T> keys, IWorker<T> worker, int lockTime) throws Exception;
}
